// pages/replacement/replacement.js
const db=wx.cloud.database();
const _ = db.command;
//时间转换函数
import common from "../../utils/getMyData.js";

Page({

  /**
   * 页面的初始数据
   */
  data: {
    //普通上拉菜单
    show1:false,     //控制弹出层是否弹出的值
    gender_patient_sex:'',        //选择性别之后的值进行页面显示
    show6:false,
    gender_patient_blood:"",
    show2:false,
    gender_adult_sex:'',
    show3:false,
    gender_adult_blood:'',
    show4:false,
    gender_child_sex:'',
    show5:false,
    gender_child_blood:'',
    show7:false,
    gender_adult_bed:'',
    show8:false,
    gender_child_bed:'',
    
    // 手术日期时间选择器
    show_opertime:false,
    gender_opertime:'',
    // show_patient_others_time:"",  //添加更多
    // gender_patient_others_time:"",  //添加更多
    currentDate: new Date().getTime(),
    maxDate: new Date().getTime(),
    formatter(type, value) {
      if (type === 'year') {
        return `${value}年`;
      } else if (type === 'month') {
        return `${value}月`;
      }
      return value;
    },
    //交班日期选择器
    show_ward_time:false,
    gender_ward_time:'',
    currentDate_ward_time: new Date().getTime(),
    maxDate_ward_time: new Date().getTime(),
    minDate_ward_time: new Date().getTime(),
    formatter(type, value) {
      if (type === 'year') {
        return `${value}年`;
      } else if (type === 'month') {
        return `${value}月`;
      }
      return value;
    },
    // 值班表时间选择器
    show_sche_time:false,
    gender_sche_time:'',
    currentDate_sche_time: new Date().getTime(),
    minDate_sche_time: new Date().getTime(),


    //下拉框显示
    // getPatientIdToAo:"",
    // getPatientIdToSs:"",
    getChiefIdToPatient:"",   show_patient_chief:false,  gender_patient_chief:"",//新增患者页面的主管医师上拉框
    getChiefIdToPatient2:"",  show_patient_otherchief:false,  gender_patient_otherchief:"",//新增患者页面的主管医师上拉框(结合添加更多）
    getPatientIdToAo:"",   show_ao_patient_id:false,  gender_ao_patient_id:"",//术后指标页面的病人姓名上拉框
    getPatientIdToSs:"",   show_ss_patient_id:false,  gender_ss_patient_id:"",//特殊交班页面的病人姓名上拉框
    getPatientIdToWa:"",   show_ward_opername:false,  gender_ward_opername:"",//特殊交班页面的病人姓名上拉框(结合添加更多，添加更多由两个组合)
    getChiefIdToSc1:"",  show_sche_morechief:false,  gender_sche_morechief:"",//值班表页面的医师上拉框(结合添加更多）
    getChiefIdToSc2:"",  show_sche_moredeputy:false,  gender_sche_moredeputy:"",//值班表页面的医师上拉框(结合添加更多）
    getChiefIdToSc3:"",  show_sche_moreattend:false,  gender_sche_moreattend:"",//值班表页面的医师上拉框(结合添加更多）
    getChiefIdToSc4:"",  show_sche_moreattend:false,  gender_sche_moreattend:"",//值班表页面的医师上拉框(结合添加更多）
    getChiefIdToSc5:"",  show_sche_moreattend:false,  gender_sche_moreattend:"",//值班表页面的医师上拉框(结合添加更多）

    ss_value:"",  //自动输入需要确定的value
    ss_bed:"",ss_sex:"",ss_age:"",ss_situation:"",//需要自动输入的值
    getPatientIdToWard:"",
    getChiefIdToSche:"", show_chief_otherchief:false,  gender_chief_otherchief:"", //值班表页面的医师上拉框合一
    getChiefIdToSche2:"",  //值班表页面的表格医师

    //总体情况数据
    ward_patient_number:"",

    //页面切换属性
    active: 0,
    active_bo: 1,
    active_sche: 1,

    //下拉框
    // option1: [
    //   { text: '病人姓名', value: 0 },
    // ],
    // value1: 0,
    // option2: [
    //   { text: '病人姓名', value: 0 },
    // ],
    // value2: 0,
    // option3: [
    //   { text: '2018', value: 0 },
    //   { text: '2019', value: 1 },
    //   { text: '2020', value: 2 },
    //   { text: '2021', value: 3 },
    //   { text: '2022', value: 4 },
    //   { text: '2023', value: 5 },
    //   { text: '2024', value: 6 },
    //   { text: '2025', value: 7 },
    //   { text: '2026', value: 8 },
    //   { text: '2027', value: 9 },
    //   { text: '2028', value: 10 },
    //   { text: '2029', value: 11 },
    // ],
    // value3: 2,
    // option4: [
    //   { text: '1', value: 0 },
    //   { text: '2', value: 1 },
    //   { text: '3', value: 2 },
    //   { text: '4', value: 3 },
    //   { text: '5', value: 4 },
    //   { text: '6', value: 5 },
    //   { text: '7', value: 6 },
    //   { text: '8', value: 7 },
    //   { text: '9', value: 8 },
    //   { text: '10', value: 9 },
    //   { text: '11', value: 10 },
    //   { text: '12', value: 11 },
    // ],
    // value4: 0,
    //总体情况
    // option5: [
    //   { text: '病人姓名', value: 0 },
    // ],
    // value5: 0,
  

    //因为按钮处要进行wx:if判断，所以要将所有输入框的数据声明
    //新增患者页面
    patient_name:"",
    patient_bed:"",
    patient_sex:"",
    patient_age:"",
    patient_blood_type:"",
    patient_chief:"",
    patient_diag:"",
    patient_treat:"", 
    patient_oper_list_name:"",
    patient_oper_list_time:"",
    //术后指标页面
    ao_patient_id:"",
    ao_WBC:"",
    ao_HB:"",
    ao_PLT:"",
    ao_TB:"",
    ao_ALT:"",
    ao_AST:"",
    ao_GGT:"",
    ao_ALB:"",
    ao_ALP:"",
    ao_FKnongdu:"",
    ao_FK:"",
    ao_jisu:"",
    ao_Tguan:"",
    ao_tiwen:"",
    ao_ruliang:"",
    ao_chuliang:"",
    ao_niaoliang:"",
    ao_desc:"",
    //特殊交班页面
    ss_patient_id:"",
    ss_temper_top:"",
    ss_temper_down:"",
    ss_rate_top:"",
    ss_rate_down:"",
    ss_press_top:"",
    ss_press_down:"",
    ss_blood_oxygen:"",
    ss_mind:"",
    ss_vision:"",
    ss_touch:"",
    ss_knock:"",
    ss_hear:"",
    ss_desc:"",
    ss_examine:"",
    ss_yester_desc:"",
    //移植术前成人页面
    bo_name_adult:"",
    bo_bed_adult:"",
    bo_sex_adult:"",
    bo_age_adult:"",
    bo_height_adult:"",
    bo_weight_adult:"",
    bo_blood_type_adult:"",
    bo_situation_adult:"",
    bo_meld_adult:"",
    bo_child_adult:"",
    bo_diag_adult:"",
    //移植术前儿童页面
    bo_name_child:"",
    bo_bed_child:"",
    bo_sex_child:"",
    bo_age_child:"",
    bo_height_child:"",
    bo_weight_child:"",
    bo_blood_type_child:"",
    bo_situation_child:"",
    bo_peld_child:"",
    bo_child_child:"",
    bo_diag_child:"",
    //总体情况页面
    ward_time:"",
    ward_turnbed:"",
    ward_turnbed_again:"",
    ward_add_bed:"",
    // ward_bef_A:"",
    // ward_bef_B:"",
    // ward_bef_AB:"",
    // ward_bef_O:"",
    // ward_wait_A:"",
    // ward_wait_B:"",
    // ward_wait_AB:"",
    // ward_wait_O:"",
    //值班表页面
    sche_group:"",
    sche_chief:"",
    sche_deputy_chief:"",
    sche_attend_doc:"",
    sche_resi_doc:"",
    sche_rota_doc:"",
    sche_desc:""
  },

  //页内标签切换
  onChange_all(event) {
    console.log(event.detail);
    
    if(event.detail.index==3){
      this.setData({
        active_bo:0,
      })
    }

    // wx.showToast({
    //   title: `切换到标签 ${event.detail.name}`,
    //   icon: 'none',
    // });
  },

  //输入框回调
  onChange(e) {
    //输入框
    console.log(e.detail);   
    //console.log(cloud.getWXContext().openid)
    this.setData({
      //因为按钮处要进行wx:if判断，所以要将所有输入框的数据声明
      [e.target.dataset.key]:e.detail
    })
  },
  //总体情况今日手术手术名称输入框（结合添加更多）
  onChange_ward_operdes(e) {
    //输入框
    console.log(e.detail);   
    this.setData({
      //因为按钮处要进行wx:if判断，所以要将所有输入框的数据声明
      [e.target.dataset.key]:e.detail
    })
    //获取ward_oper的des属性并改变数组（结合添加更多）
    this.data.ward_oper[e.currentTarget.dataset.index].des=e.detail
    this.setData({
      ward_oper:this.data.ward_oper
    })
    //判断今日手术部分是否都不是空的
    var ward_judge=true
    for(var i=0;i<this.data.ward_oper.length;i++){
      if(this.data.ward_oper[i].name==''||this.data.ward_oper[i].des==''){
        ward_judge=false;
        break;
      }
    }
    this.setData({
      ward_judge:ward_judge
    })
  },
  //总体情况今日手术病人姓名输入框（结合添加更多）
  onChange_ward_opername(e) {
    //输入框
    console.log(e.detail);   
    this.setData({
      //因为按钮处要进行wx:if判断，所以要将所有输入框的数据声明
      [e.target.dataset.key]:e.detail
    })
    //判断今日手术部分是否都不是空的
    var ward_judge=true
    for(var i=0;i<this.data.ward_oper.length;i++){
      if(this.data.ward_oper[i].name==''||this.data.ward_oper[i].des==''){
        ward_judge=false;
        break;
      }
    }
    this.setData({
      ward_judge:ward_judge
    })
  },
  //总体情况拟住院约床输入框（结合添加更多）
  onChange_ward_bed_appoint(e) {
    //输入框
    console.log(e.detail);   
    this.setData({
      //因为按钮处要进行wx:if判断，所以要将所有输入框的数据声明
      [e.target.dataset.key]:e.detail
    })
    //获取ward_oper的des属性并改变数组（结合添加更多）
    this.data.ward_bed_appoint[e.currentTarget.dataset.index]=e.detail
    this.setData({
      ward_bed_appoint:this.data.ward_bed_appoint
    })
  },
  //总体情况900医院输入框（结合添加更多）
  onChange_ward_others_hos(e) {
    //输入框
    console.log(e.detail);   
    this.setData({
      //因为按钮处要进行wx:if判断，所以要将所有输入框的数据声明
      [e.target.dataset.key]:e.detail
    })
    //获取ward_oper的des属性并改变数组（结合添加更多）
    this.data.ward_others_hos[e.currentTarget.dataset.index]=e.detail
    this.setData({
      ward_others_hos:this.data.ward_others_hos,
    })
  },
  //术后指标的指标数据名字（结合添加更多）
  onChange_ao_others_name(e) {
    //输入框
    console.log(e.detail);   
    this.setData({
      //因为按钮处要进行wx:if判断，所以要将所有输入框的数据声明
      [e.target.dataset.key]:e.detail
    })
    //获取ward_oper的des属性并改变数组（结合添加更多）
    this.data.ao_others[e.currentTarget.dataset.index].name=e.detail
    this.setData({
      ao_others:this.data.ao_others
    })
  },
  //术后指标的指标数据数值（结合添加更多）
  onChange_ao_others_value(e) {
    //输入框
    console.log(e.detail);   
    this.setData({
      //因为按钮处要进行wx:if判断，所以要将所有输入框的数据声明
      [e.target.dataset.key]:e.detail
    })
    //获取ward_oper的des属性并改变数组（结合添加更多）
    this.data.ao_others[e.currentTarget.dataset.index].value=e.detail
    this.setData({
      ao_others:this.data.ao_others
    })
  },
  //术后指标的指标数据名字（结合添加更多）
  onChange_patient_others_name(e) {
    //输入框
    console.log(e.detail);   
    this.setData({
      //因为按钮处要进行wx:if判断，所以要将所有输入框的数据声明
      [e.target.dataset.key]:e.detail
    })
    //获取ward_oper的des属性并改变数组（结合添加更多）
    this.data.patient_others[e.currentTarget.dataset.index].name=e.detail
    this.setData({
      patient_others:this.data.patient_others
    })
  },


  //提交表单添加进数据库
  btnSub_patient(res){
      var {patient_name,patient_bed,patient_sex,patient_age,patient_blood_type,patient_diag,patient_treat,patient_oper_list_name}=res.detail.value
       //进入加载页面
       wx.showLoading({
        title: '加载中...',
        mask: true
        })
        setTimeout(function () {
          wx.hideLoading()
        }, 2000)
        console.log(this.data)

      //在本地改ward表中新入院
      //每提交一次新入院加一
        db.collection("ward").where({
          ward_submit:false
        }).update({
              data:{
                ward_in:_.push([patient_name])
              } 
        })

      //云函数调用
      wx.cloud.callFunction({
          name:"newAdd",
          data:{
            action:'patient',
            patient_name:patient_name,
            patient_bed:patient_bed,
            patient_sex:patient_sex,
            patient_age:patient_age,
            patient_blood_type:patient_blood_type,
            patient_chief:this.data.patient_chief,
            patient_diag:patient_diag,
            patient_treat:patient_treat, 
            patient_oper_list_name:patient_oper_list_name,
            patient_oper_list_time:this.data.patient_oper_list_time,
            patient_others:this.data.patient_others,
            patient_otherchief:this.data.patient_otherchief
        }
      }).then(res=>{
        console.log(res)
        //清除填写内容
        this.setData({
          //清空value
          value:"",
          gender_patient_sex:"",
          gender_patient_blood:"",
          gender_opertime:"",
          gender_patient_chief:"",
          gender_patient_otherchief:[],
          show_patient_otherchief:[],
          message:"",
          //清空值
          patient_name:"",
          patient_bed:"",
          patient_sex:"",
          patient_age:"",
          patient_blood_type:"",
          patient_chief:"",
          patient_diag:"",
          patient_treat:"", 
          patient_oper_list_name:"",
          patient_oper_list_time:"",
          patient_others:"",
          patient_otherchief:""
        })
      })
  },
  btnSub_ao(res){
    var {ao_WBC,ao_HB,ao_PLT,ao_TB,ao_ALT,ao_AST,ao_GGT,ao_ALB,ao_ALP,ao_FK浓度,ao_FK,ao_激素,ao_T管,ao_体温,ao_入量,ao_出量,ao_尿量,ao_desc}=res.detail.value
      //进入加载页面
      wx.showLoading({
        title: '加载中...',
        mask: true
        })
        setTimeout(function () {
          wx.hideLoading()
        }, 2000)
      wx.cloud.callFunction({
        name:"newAdd",
        data:{
          action:'ao',
          // patient_id:this.data.getPatientIdToAo[ao_patient_id-1]._id, 
          patient_id:this.data.ao_patient_id,
          ao_WBC:ao_WBC,
          ao_HB:ao_HB,
          ao_PLT:ao_PLT,
          ao_TB:ao_TB,
          ao_ALT:ao_ALT,
          ao_AST:ao_AST,
          ao_GGT:ao_GGT,
          ao_ALB:ao_ALB,
          ao_ALP:ao_ALP,
          ao_FK浓度:ao_FK浓度,
          ao_FK:ao_FK,
          ao_激素:ao_激素,
          ao_T管:ao_T管,
          ao_体温:ao_体温,
          ao_入量:ao_入量,
          ao_出量:ao_出量,
          ao_尿量:ao_尿量,
          ao_desc:ao_desc,
          ao_others:this.data.ao_others
        }
      }).then(res=>{
        console.log(res)
        //清除填写内容
        this.setData({
          //清空value
          value1:0,
          value:"",
          message:"",
          gender_ao_patient_id:"",
          //清空值
          ao_patient_id:"",
          ao_WBC:"",
          ao_HB:"",
          ao_PLT:"",
          ao_TB:"",
          ao_ALT:"",
          ao_AST:"",
          ao_GGT:"",
          ao_ALB:"",
          ao_ALP:"",
          ao_FKnongdu:"",
          ao_FK:"",
          ao_jisu:"",
          ao_Tguan:"",
          ao_tiwen:"",
          ao_ruliang:"",
          ao_chuliang:"",
          ao_niaoliang:"",
          ao_desc:"",
          ao_others:""
        })
      })
  },
  btnSub_ss(res){
    var {ss_temper_top,ss_temper_down,ss_rate_top,ss_rate_down,ss_press_top,ss_press_down,ss_blood_oxygen,ss_mind,ss_vision,ss_touch,ss_knock,ss_hear,ss_desc,ss_examine,ss_yester_desc,ss_patient_id}=res.detail.value
      //进入加载页面
      wx.showLoading({
        title: '加载中...',
        mask: true
        })
        setTimeout(function () {
          wx.hideLoading()
        }, 2000)
      wx.cloud.callFunction({
        name: 'login'
      }).then(res => {
        console.log(res)
        wx.cloud.callFunction({
          name:"newAdd",
          data:{
            action:'ss',
            ss_openid:res.result.openid,
            // patient_id:this.data.getPatientIdToSs[ss_patient_id-1].patient_id, 
            patient_id:this.data.ss_patient_id,
            ss_temper_top:ss_temper_top,
            ss_temper_down:ss_temper_down,
            ss_rate_top:ss_rate_top,
            ss_rate_down:ss_rate_down,
            ss_press_top:ss_press_top,
            ss_press_down:ss_press_down,
            ss_blood_oxygen:ss_blood_oxygen,
            ss_mind:ss_mind,
            ss_vision:ss_vision,
            ss_touch:ss_touch,
            ss_knock:ss_knock,
            ss_hear:ss_hear,
            ss_desc:ss_desc,
            ss_examine:ss_examine,
            ss_yester_desc:ss_yester_desc
          }
        })
      }).then(res=>{
        console.log(res)
        //清除填写内容
        this.setData({
          //清空value
          value2:0,
          ss_bed:"",
          ss_sex:"",
          ss_age:"",
          ss_situation:"",
          value:"",
          message:"",
          gender_ss_patient_id:"",
          //清空值
          ss_patient_id:"",
          ss_temper_top:"",
          ss_temper_down:"",
          ss_rate_top:"",
          ss_rate_down:"",
          ss_press_top:"",
          ss_press_down:"",
          ss_blood_oxygen:"",
          ss_mind:"",
          ss_vision:"",
          ss_touch:"",
          ss_knock:"",
          ss_hear:"",
          ss_desc:"",
          ss_examine:"",
          ss_yester_desc:""
        })
      })
  },
  btnSub_bo_adult(res){
    var {bo_name,bo_bed,bo_sex,bo_age,bo_height,bo_weight,bo_blood_type,bo_situation,bo_meld,bo_child,bo_diag}=res.detail.value
     //进入加载页面
     wx.showLoading({
      title: '加载中...',
      mask: true
      })
      setTimeout(function () {
        wx.hideLoading()
      }, 2000)
    wx.cloud.callFunction({
      name:"newAdd",
      data:{
        action:'bo_adult',
        bo_age_type:"成人",
        bo_name:bo_name,
        bo_bed:bo_bed,
        bo_sex:bo_sex,
        bo_age:bo_age,
        bo_height:bo_height,
        bo_weight:bo_weight,
        bo_blood_type:bo_blood_type,
        bo_situation:bo_situation,
        bo_meld:bo_meld,
        bo_child:bo_child,
        bo_diag:bo_diag,
        bo_del:false
      }
    }).then(res=>{
      console.log(res)
      //清除填写内容
      this.setData({
        //清空value
        value:"",
        gender_patient_sex:"",
        gender_adult_bed:"",
        gender_adult_sex:"",
        gender_adult_blood:"",
        message:"",
        //清空值
        bo_name_adult:"",
        bo_bed_adult:"",
        bo_sex_adult:"",
        bo_age_adult:"",
        bo_height_adult:"",
        bo_weight_adult:"",
        bo_blood_type_adult:"",
        bo_situation_adult:"",
        bo_meld_adult:"",
        bo_child_adult:"",
        bo_diag_adult:""
      })
    })
  },
  btnSub_bo_child(res){
    var {bo_name,bo_bed,bo_sex,bo_age,bo_height,bo_weight,bo_blood_type,bo_situation,bo_peld,bo_child,bo_diag}=res.detail.value
     //进入加载页面
     wx.showLoading({
      title: '加载中...',
      mask: true
      })
      setTimeout(function () {
        wx.hideLoading()
      }, 2000)
    wx.cloud.callFunction({
      name:"newAdd",
      data:{
        action:'bo_child',
        bo_age_type:"儿童",
        bo_name:bo_name,
        bo_bed:bo_bed,
        bo_sex:bo_sex,
        bo_age:bo_age,
        bo_height:bo_height,
        bo_weight:bo_weight,
        bo_blood_type:bo_blood_type,
        bo_situation:bo_situation,
        bo_peld:bo_peld,
        bo_child:bo_child,
        bo_diag:bo_diag,
        bo_del:false
      }
    }).then(res=>{
      console.log(res)
      //清除填写内容
      this.setData({
        //清空value
        value:"",
        gender_patient_sex:"",
        gender_child_bed:"",
        gender_child_sex:"",
        gender_child_blood:"",
        message:"",
        //清空值
        bo_name_child:"",
        bo_bed_child:"",
        bo_sex_child:"",
        bo_age_child:"",
        bo_height_child:"",
        bo_weight_child:"",
        bo_blood_type_child:"",
        bo_situation_child:"",
        bo_peld_child:"",
        bo_child_child:"",
        bo_diag_child:""
      })
    })
  },
  btnSub_ward(res){
    var {ward_turnbed,ward_turnbed_again,ward_add_bed}=res.detail.value
    //,ward_bef_A,ward_bef_B,ward_bef_AB,ward_bef_O,ward_wait_A,ward_wait_B,ward_wait_AB,ward_wait_O
     //进入加载页面
     wx.showLoading({
      title: '加载中...',
      mask: true
      })
      setTimeout(function () {
        wx.hideLoading()
      }, 2000)
    
    //在本地改patient表中病人手术
    //今日手术修改patient表所需的变量，ward_patientid[]根据病人姓名查到_id，ward_patient_oper_list[i]将加好了的数组存到数组
    var ward_patientid=[]
    var ward_patient_oper_list=[]
    var j=0
    for(var i=0;i<this.data.ward_oper.length;i++){
      db.collection('patient').where({
        patient_name:this.data.ward_oper[i].name
      }).get().then(res=>{
        ward_patientid.push(res.data[0]._id)
        ward_patient_oper_list.push(res.data[0].patient_oper_list)
        ward_patient_oper_list[j].push({"name":this.data.ward_oper[j].des,"time":new Date(this.data.ward_time)})
      }).then(res=>{
          db.collection('patient').doc(ward_patientid[j]).update({
              data:{
                patient_oper_list:ward_patient_oper_list[j]
              }
          })
          j++
      })
    }
    
    wx.cloud.callFunction({
      name:"newAdd",
      data:{
        action:'ward',
        ward_turnbed:ward_turnbed,
        ward_turnbed_again:ward_turnbed_again,
        ward_add_bed:ward_add_bed,
        ward_bef_A:this.data.ward_bef_A,
        ward_bef_B:this.data.ward_bef_B,
        ward_bef_AB:this.data.ward_bef_AB,
        ward_bef_O:this.data.ward_bef_O,
        ward_wait_A:this.data.ward_wait_A,
        ward_wait_B:this.data.ward_wait_B,
        ward_wait_AB:this.data.ward_wait_AB,
        ward_wait_O:this.data.ward_wait_O,
        ward_oper:this.data.ward_oper,
        ward_bed_appoint:this.data.ward_bed_appoint,
        ward_others_hos:this.data.ward_bed_appoint,
        ward_time:this.data.ward_time,
        ward_lastid:this.data.ward_lastid,
      }
    }).then(res=>{
      console.log(res)
      //清除填写内容
      this.setData({
        //清空value
        value:"",
        message:"",
        gender_ward_opername:[],
        show_ward_opername:[],
        //清空值
        ward_turnbed:"",
        ward_turnbed_again:"",
        ward_add_bed:"",
        // ward_bef_A:"",
        // ward_bef_B:"",
        // ward_bef_AB:"",
        // ward_bef_O:"",
        // ward_wait_A:"",
        // ward_wait_B:"",
        // ward_wait_AB:"",
        // ward_wait_O:""
        ward_oper:[],
        //value5:0,
        ward_bed_appoint:"",
        ward_others_hos:""
      })
        //交班日期要查数据库
        db.collection("ward").where({
          ward_submit:false
        }).get().then(res=>{
          if(res.data[0].ward_time.getTime()>new Date().getTime()){
            this.setData({
            minDate_ward_time:res.data[0].ward_time.getTime(),
            ward_time:res.data[0].ward_time.getTime(),
            gender_ward_time:"",
            ward_lastid:res.data[0]._id
            })
          }else{
            this.setData({
              minDate_ward_time:res.data[0].ward_time.getTime(),
              ward_time:res.data[0].ward_time.getTime(),
              gender_ward_time:common.getMyData(res.data[0].ward_time.getTime(),'Y-m-d'),
              ward_lastid:res.data[0]._id
            })
          }
        })
          this.setData({
            minDate_ward_time:this.data.minDate_ward_time,
            ward_time:this.data.ward_time,
            gender_ward_time:this.data.gender_ward_time,
            ward_lastid:this.data.ward_lastid
          })
    })
  },
  btnSub_sche(res){
    var {sche_group,sche_chief,sche_deputy_chief,sche_attend_doc,sche_resi_doc,sche_rota_doc,sche_discuss_time,sche_in_consul,sche_out_consul,sche_department,sche_desc,sche_rest_time1,sche_rest_time2,sche_pub_edu1,sche_pub_edu2,sche_month,sche_year}=res.detail.value
    if(sche_rest_time1=="") sche_rest_time1="许艺超"
    if(sche_rest_time2=="") sche_rest_time2="周末"
    if(sche_discuss_time=="") sche_discuss_time="必要时"
    if(sche_in_consul=="") sche_in_consul="当日值班二线"
    if(sche_out_consul=="") sche_out_consul="科主任或指定"
    if(sche_department=="") sche_department="主任轮流"
    if(1) sche_year+=2018
    if(1) sche_month+=1
    console.log(res.detail)
     //进入加载页面
     wx.showLoading({
      title: '加载中...',
      mask: true
      })
      setTimeout(function () {
        wx.hideLoading()
      }, 2000)
    wx.cloud.callFunction({
      name:"newAdd",
      data:{
        action:'sche',
        sche_month:this.data.sche_time,
        sche_group:sche_group,
        //patient_id:this.data.getPatientIdToSs[ss_patient_id-1].patient_id, 
        sche_chief:this.data.sche_otherchief[0],
        sche_deputy_chief:this.data.sche_otherchief[1],
        sche_attend_doc:this.data.sche_otherchief[2],
        sche_resi_doc:this.data.sche_otherchief[3],
        sche_rota_doc:this.data.sche_otherchief[4],
        sche_morechief:this.data.sche_morechief,
        sche_moredeputy:this.data.sche_moredeputy,
        sche_moreattend:this.data.sche_moreattend,
        sche_moreresi:this.data.sche_moreresi,
        sche_morerota:this.data.sche_morerota,
        sche_rest_time:this.data.sche_otherchief[5]+"/"+sche_rest_time2,
        sche_discuss_time:sche_discuss_time,
        sche_pub_edu:this.data.sche_otherchief[6]+"/"+this.data.sche_otherchief[7],
        sche_in_consul:sche_in_consul,
        sche_out_consul:sche_out_consul,
        sche_department:sche_department,
        sche_desc:sche_desc,
        sche_day_list:this.data.sche_list
      }
    }).then(res=>{
      console.log(res)
      //清除填写内容
      this.setData({
        //清空value
        value:"",
        message:"",
        gender_sche_otherchief:["","","","","","","",""],
        gender_sche_time:[],
        gender_sche_morechief:[],
        gender_sche_moredeputy:[],
        gender_sche_moreattend:[],
        gender_sche_moreresi:[],
        gender_sche_morerota:[],
        gender_sche_list:[],
        show_sche_otherchief:["","","","","","","",""],
        show_sche_morechief:[],
        show_sche_moredeputy:[],
        show_sche_moreattend:[],
        show_sche_moreresi:[],
        show_sche_morerota:[],
        show_sche_list:[],
 
        //清空值
        sche_time:"",
        sche_group:"",
        sche_chief:"",
        sche_deputy_chief:"",
        sche_attend_doc:"",
        sche_resi_doc:"",
        sche_rota_doc:"",
        sche_otherchief:["","","","","","","",""],
        sche_time:[],
        sche_morechief:[],
        sche_moredeputy:[],
        sche_moreattend:[],
        sche_moreresi:[],
        sche_morerota:[],
        sche_list:[]
      })
    })
  },


  //新增患者页面上拉菜单/性别
  showPopup_patient_sex(e){      //点击选择性别，打开弹出层（选择器）
    this.setData({
      columns_patient_sex: ['男','女'],   //选择器中的值
      show1:true
    })
  },
  onClose_patient_sex() {     //点击空白处开闭弹出层（选择器）及选择器左上角的取消
    this.setData({ show1: false });
  },
  onConfirm_patient_sex(e){    //选择器右上角的确定，点击确定获取值
    this.setData({
      gender_patient_sex:e.detail.value,
      patient_sex:e.detail.value,
      show1:false
    })
  },
  //新增患者页面上拉菜单/血型
  showPopup_patient_blood(e){      //点击选择性别，打开弹出层（选择器）
    this.setData({
      columns_patient_blood: ['A','B','AB','O'],   //选择器中的值
      show6:true
    })
  },
  onClose_patient_blood() {     //点击空白处开闭弹出层（选择器）及选择器左上角的取消
    this.setData({ show6: false });
  },
  onConfirm_patient_blood(e){    //选择器右上角的确定，点击确定获取值
    this.setData({
      gender_patient_blood:e.detail.value,
      patient_blood_type:e.detail.value,
      show6:false
    })
  },
    //新增患者页面主管医师上拉框
  showPopup_patient_chief(e){      //点击选择性别，打开弹出层（选择器）
    db.collection("user").where({
    }).get().then(res=>{
      this.setData({
        getChiefIdToPatient:res.data,
        patient_chief:"",
        columns_patient_chief:[]
      })
      for(var i=0;i<res.data.length;i++){
        this.data.columns_patient_chief[i]=res.data[i].user_name
      }
      this.setData({
        columns_patient_chief:this.data.columns_patient_chief,
      })
    })
    this.setData({
      //columns_opertime: ['A','B','AB','O'],   //选择器中的值
      show_patient_chief:true
    })
  },
  onClose_patient_chief() {     //点击空白处开闭弹出层（选择器）及选择器左上角的取消
    this.setData({ show_patient_chief: false });
  },
  onConfirm_patient_chief(e){    //选择器右上角的确定，点击确定获取值
    this.data.patient_chief=this.data.getChiefIdToPatient[e.detail.index].user_name
    this.setData({
      gender_patient_chief:e.detail.value,
      patient_chief:this.data.patient_chief,
      show_patient_chief:false
    })
  },
  //术后指标页面病人姓名上拉框
  showPopup_ao_patient_id(e){      //点击选择性别，打开弹出层（选择器）
    db.collection("patient").where({
      patient_del:false
    }).get().then(res=>{
      this.setData({
        getPatientIdToAo:res.data,
        ao_patient_id:"",
        columns_ao_patient_id:[]
      })
      for(var i=0;i<res.data.length;i++){
        this.data.columns_ao_patient_id[i]=res.data[i].patient_name
      }
      this.setData({
        columns_ao_patient_id:this.data.columns_ao_patient_id,
      })
    })
    this.setData({
      //columns_opertime: ['A','B','AB','O'],   //选择器中的值
      show_ao_patient_id:true
    })
  },
  onClose_ao_patient_id() {     //点击空白处开闭弹出层（选择器）及选择器左上角的取消
    this.setData({ show_ao_patient_id: false });
  },
  onConfirm_ao_patient_id(e){    //选择器右上角的确定，点击确定获取值
    this.data.ao_patient_id=this.data.getPatientIdToAo[e.detail.index]._id
    this.setData({
      gender_ao_patient_id:e.detail.value,
      ao_patient_id:this.data.ao_patient_id,
      show_ao_patient_id:false
    })
  },
  //特殊交班页面病人姓名上拉框
  showPopup_ss_patient_id(e){      //点击选择性别，打开弹出层（选择器）
    db.collection("patient").where({
      patient_del:false
    }).get().then(res=>{
      this.setData({
        getPatientIdToSs:res.data,
        ss_patient_id:"",
        columns_ss_patient_id:[]
      })
      for(var i=0;i<res.data.length;i++){
        this.data.columns_ss_patient_id[i]=res.data[i].patient_name
      }
      this.setData({
        columns_ss_patient_id:this.data.columns_ss_patient_id,
      })
    })
    this.setData({
      //columns_opertime: ['A','B','AB','O'],   //选择器中的值
      show_ss_patient_id:true
    })
  },
  onClose_ss_patient_id() {     //点击空白处开闭弹出层（选择器）及选择器左上角的取消
    this.setData({ show_ss_patient_id: false });
  },
  onConfirm_ss_patient_id(e){    //选择器右上角的确定，点击确定获取值
    this.data.ss_patient_id=this.data.getPatientIdToSs[e.detail.index]._id
    this.setData({
      gender_ss_patient_id:e.detail.value,
      ss_patient_id:this.data.ss_patient_id,
      show_ss_patient_id:false
    })

    console.log(e)
    // 判断当前时间和手术时间，给ss_situation赋值
    this.data.ss_situation=""     //先将ss_situation清零
    if(e.detail!=0){
      for(var i=0;i<this.data.getPatientIdToSs[e.detail.index].patient_oper_list.length;i++){
        this.data.ss_situation=this.data.ss_situation+this.data.getPatientIdToSs[e.detail.index].patient_oper_list[i].name
        if(new Date().getTime()>=this.data.getPatientIdToSs[e.detail.index].patient_oper_list[i].time){
          this.data.ss_situation=this.data.ss_situation+"术后  "
        }else{
          this.data.ss_situation=this.data.ss_situation+"术前  "
        }
      }
      if(this.data.getPatientIdToSs[e.detail.index].patient_oper_list.length==0){
        this.data.ss_situation=this.data.ss_situation+"无"
      }
      this.setData({
        value2:e.detail,
        ss_value:e.detail,
        ss_bed:this.data.getPatientIdToSs[e.detail.index].patient_bed,
        ss_sex:this.data.getPatientIdToSs[e.detail.index].patient_sex,
        ss_age:this.data.getPatientIdToSs[e.detail.index].patient_age,
        ss_situation:this.data.ss_situation
      })
    }
  },
  //总体情况页面今日手术病人姓名上拉框(结合添加更多)（且和手术名称共同组成一组添加更多，不要轻易为原型）
  showPopup_ward_opername(e){      //点击选择性别，打开弹出层（选择器）
    db.collection("patient").where({
      patient_del:false
    }).get().then(res=>{
      this.setData({
        getPatientIdToWa:res.data,
        columns_ward_opername:[]
      })
      for(var i=0;i<res.data.length;i++){
        this.data.columns_ward_opername[i]=res.data[i].patient_name
      }
      this.setData({
        columns_ward_opername:this.data.columns_ward_opername,
      })
    })
    this.data.show_ward_opername[e.currentTarget.dataset.index]=true
    this.setData({
      //columns_opertime: ['A','B','AB','O'],   //选择器中的值
      show_ward_opername: this.data.show_ward_opername
    })
  },
  onClose_ward_opername(e) {     //点击空白处开闭弹出层（选择器）及选择器左上角的取消
    for(var i=0;i<this.data.show_ward_opername.length;i++){
      this.data.show_ward_opername[i]=false
    }
    this.data.show_ward_opername[e.currentTarget.dataset.index]=false
    this.setData({ show_ward_opername: this.data.show_ward_opername });
  },
  onConfirm_ward_opername(e){    //选择器右上角的确定，点击确定获取值
    this.data.show_ward_opername[e.currentTarget.dataset.index]=false
    this.data.gender_ward_opername[e.currentTarget.dataset.index]=e.detail.value
    this.data.ward_oper[e.currentTarget.dataset.index].name=this.data.getPatientIdToWa[e.detail.index].patient_name
    this.setData({
      gender_ward_opername:this.data.gender_ward_opername,
      ward_oper:this.data.ward_oper,
      show_ward_opername:this.data.show_ward_opername
    })
  },
  //移植术前页面上拉菜单/成人性别
  showPopup_adult_bed(e){      //点击选择性别，打开弹出层（选择器）
    this.setData({
      // columns_adult:[
      //   //第一列
      //   {
      //     values:['男','女']  //选择器中的值
      //   },
      //   //第二列
      //   {
      //     values:['A','B','AB','O']   //选择器中的值
      //   },
      // ],
      columns_adult_bed: ['院内','院外','儿科'],   //选择器中的值
      show7:true
    })
  },
  onClose_adult_bed() {     //点击空白处开闭弹出层（选择器）及选择器左上角的取消
    this.setData({ show7: false });
  },
  onConfirm_adult_bed(e){    //选择器右上角的确定，点击确定获取值
    this.setData({
      gender_adult_bed:e.detail.value,
      bo_sex_adult:e.detail.value,
      show7:false
    })
  },
  //移植术前页面上拉菜单/成人性别
  showPopup_adult_sex(e){      //点击选择性别，打开弹出层（选择器）
    this.setData({
      columns_adult_sex: ['男','女'],   //选择器中的值
      show2:true
    })
  },
  onClose_adult_sex() {     //点击空白处开闭弹出层（选择器）及选择器左上角的取消
    this.setData({ show2: false });
  },
  onConfirm_adult_sex(e){    //选择器右上角的确定，点击确定获取值
    this.setData({
      gender_adult_sex:e.detail.value,
      bo_sex_adult:e.detail.value,
      show2:false
    })
  },
  //移植术前页面上拉菜单/成人血型
  showPopup_adult_blood(e){      //点击选择性别，打开弹出层（选择器）
    this.setData({
      columns_adult_blood: ['A','B','AB','O'],   //选择器中的值
      show3:true
    })
  },
  onClose_adult_blood() {     //点击空白处开闭弹出层（选择器）及选择器左上角的取消
    this.setData({ show3: false });
  },
  onConfirm_adult_blood(e){    //选择器右上角的确定，点击确定获取值
    this.setData({
      gender_adult_blood:e.detail.value,
      bo_blood_type_adult:e.detail.value,
      show3:false
    })
  },
  //移植术前页面上拉菜单/儿童床号
  showPopup_child_bed(e){      //点击选择性别，打开弹出层（选择器）
    this.setData({
      columns_child_bed: ['院内','院外','儿科'],   //选择器中的值
      show8:true
    })
  },
  onClose_child_bed() {     //点击空白处开闭弹出层（选择器）及选择器左上角的取消
    this.setData({ show8: false });
  },
  onConfirm_child_bed(e){    //选择器右上角的确定，点击确定获取值
    this.setData({
      gender_child_bed:e.detail.value,
      bo_bed_child:e.detail.value,
      show8:false
    })
  },
  //移植术前页面上拉菜单/儿童性别
  showPopup_child_sex(e){      //点击选择性别，打开弹出层（选择器）
    this.setData({
      columns_child_sex: ['男','女'],   //选择器中的值
      show4:true
    })
  },
  onClose_child_sex() {     //点击空白处开闭弹出层（选择器）及选择器左上角的取消
    this.setData({ show4: false });
  },
  onConfirm_child_sex(e){    //选择器右上角的确定，点击确定获取值
    this.setData({
      gender_child_sex:e.detail.value,
      bo_sex_child:e.detail.value,
      show4:false
    })
  },
  //移植术前页面上拉菜单/儿童血型
  showPopup_child_blood(e){      //点击选择性别，打开弹出层（选择器）
    this.setData({
      columns_child_blood: ['A','B','AB','O'],   //选择器中的值
      show5:true
    })
  },
  onClose_child_blood() {     //点击空白处开闭弹出层（选择器）及选择器左上角的取消
    this.setData({ show5: false });
  },
  onConfirm_child_blood(e){    //选择器右上角的确定，点击确定获取值
    this.setData({
      gender_child_blood:e.detail.value,
      bo_blood_type_child:e.detail.value,
      show5:false
    })
  },
  //新增患者页面主管医师上拉框
  showPopup_patient_chief(e){      //点击选择性别，打开弹出层（选择器）
    db.collection("user").where({
    }).get().then(res=>{
      this.setData({
        getChiefIdToPatient:res.data,
        patient_chief:"",
        columns_patient_chief:[]
      })
      for(var i=0;i<res.data.length;i++){
        this.data.columns_patient_chief[i]=res.data[i].user_name
      }
      this.setData({
        columns_patient_chief:this.data.columns_patient_chief,
      })
    })
    this.setData({
      //columns_opertime: ['A','B','AB','O'],   //选择器中的值
      show_patient_chief:true
    })
  },
  onClose_patient_chief() {     //点击空白处开闭弹出层（选择器）及选择器左上角的取消
    this.setData({ show_patient_chief: false });
  },
  onConfirm_patient_chief(e){    //选择器右上角的确定，点击确定获取值
    this.data.patient_chief=this.data.getChiefIdToPatient[e.detail.index].user_name
    this.setData({
      gender_patient_chief:e.detail.value,
      patient_chief:this.data.patient_chief,
      show_patient_chief:false
    })
  },
  //新增患者页面主管医师上拉框(结合添加更多)
  showPopup_patient_otherchief(e){      //点击选择性别，打开弹出层（选择器）
    db.collection("user").where({
    }).get().then(res=>{
      this.setData({
        getChiefIdToPatient2:res.data,
        columns_patient_otherchief:[]
      })
      for(var i=0;i<res.data.length;i++){
        this.data.columns_patient_otherchief[i]=res.data[i].user_name
      }
      this.setData({
        columns_patient_otherchief:this.data.columns_patient_otherchief,
      })
    })
    this.data.show_patient_otherchief[e.currentTarget.dataset.index]=true
    this.setData({
      //columns_opertime: ['A','B','AB','O'],   //选择器中的值
      show_patient_otherchief: this.data.show_patient_otherchief
    })
  },
  onClose_patient_otherchief(e) {     //点击空白处开闭弹出层（选择器）及选择器左上角的取消
    for(var i=0;i<this.data.show_patient_otherchief.length;i++){
      this.data.show_patient_otherchief[i]=false
    }
    this.data.show_patient_otherchief[e.currentTarget.dataset.index]=false
    this.setData({ show_patient_otherchief: this.data.show_patient_otherchief });
  },
  onConfirm_patient_otherchief(e){    //选择器右上角的确定，点击确定获取值
    this.data.show_patient_otherchief[e.currentTarget.dataset.index]=false
    this.data.gender_patient_otherchief[e.currentTarget.dataset.index]=e.detail.value
    this.data.patient_otherchief[e.currentTarget.dataset.index]=this.data.getChiefIdToPatient2[e.detail.index].user_name
    this.setData({
      gender_patient_otherchief:this.data.gender_patient_otherchief,
      patient_otherchief:this.data.patient_otherchief,
      show_patient_otherchief:this.data.show_patient_otherchief
    })
  },
  //值班表页面医师上拉框组合
  showPopup_sche_otherchief(e){      //点击选择性别，打开弹出层（选择器）
    db.collection("user").where({
    }).get().then(res=>{
      this.setData({
        getChiefIdToSche:res.data,
        columns_sche_otherchief:[]
      })
      for(var i=0;i<res.data.length;i++){
        this.data.columns_sche_otherchief[i]=res.data[i].user_name
      }
      this.setData({
        columns_sche_otherchief:this.data.columns_sche_otherchief,
      })
    })
    this.data.show_sche_otherchief[e.currentTarget.dataset.index]=true
    this.setData({
      //columns_opertime: ['A','B','AB','O'],   //选择器中的值
      show_sche_otherchief:this.data.show_sche_otherchief
    })
  },
  onClose_sche_otherchief(e) {     //点击空白处开闭弹出层（选择器）及选择器左上角的取消
    for(var i=0;i<this.data.show_sche_otherchief.length;i++){
      this.data.show_sche_otherchief[i]=false
    }
    this.data.show_sche_otherchief[e.currentTarget.dataset.index]=false
    this.setData({ show_sche_otherchief: this.data.show_sche_otherchief });
  },
  onConfirm_sche_otherchief(e){    //选择器右上角的确定，点击确定获取值
    this.data.show_sche_otherchief[e.currentTarget.dataset.index]=false
    this.data.gender_sche_otherchief[e.currentTarget.dataset.index]=e.detail.value
    this.data.sche_otherchief[e.currentTarget.dataset.index]=this.data.getChiefIdToSche[e.detail.index].user_name
    this.setData({
      gender_sche_otherchief:this.data.gender_sche_otherchief,
      sche_otherchief:this.data.sche_otherchief,
      show_sche_otherchief:this.data.show_sche_otherchief
    })
  },
  //值班表页面主任医师上拉框(结合添加更多)
  showPopup_sche_morechief(e){      //点击选择性别，打开弹出层（选择器）
    db.collection("user").where({
    }).get().then(res=>{
      this.setData({
        getChiefIdToSc1:res.data,
        columns_sche_morechief:[]
      })
      for(var i=0;i<res.data.length;i++){
        this.data.columns_sche_morechief[i]=res.data[i].user_name
      }
      this.setData({
        columns_sche_morechief:this.data.columns_sche_morechief,
      })
    })
    this.data.show_sche_morechief[e.currentTarget.dataset.index]=true
    this.setData({
      //columns_opertime: ['A','B','AB','O'],   //选择器中的值
      show_sche_morechief: this.data.show_sche_morechief
    })
  },
  onClose_sche_morechief(e) {     //点击空白处开闭弹出层（选择器）及选择器左上角的取消
    for(var i=0;i<this.data.show_sche_morechief.length;i++){
      this.data.show_sche_morechief[i]=false
    }
    this.data.show_sche_morechief[e.currentTarget.dataset.index]=false
    this.setData({ show_sche_morechief: this.data.show_sche_morechief});
  },
  onConfirm_sche_morechief(e){    //选择器右上角的确定，点击确定获取值
    this.data.show_sche_morechief[e.currentTarget.dataset.index]=false
    this.data.gender_sche_morechief[e.currentTarget.dataset.index]=e.detail.value
    this.data.sche_morechief[e.currentTarget.dataset.index]=this.data.getChiefIdToSc1[e.detail.index].user_name
    this.setData({
      gender_sche_morechief:this.data.gender_sche_morechief,
      sche_morechief:this.data.sche_morechief,
      show_sche_morechief:this.data.show_sche_morechief
    })
  },
  //值班表页面副主任医师上拉框(结合添加更多)
  showPopup_sche_moredeputy(e){      //点击选择性别，打开弹出层（选择器）
    db.collection("user").where({
    }).get().then(res=>{
      this.setData({
        getChiefIdToSc2:res.data,
        columns_sche_moredeputy:[]
      })
      for(var i=0;i<res.data.length;i++){
        this.data.columns_sche_moredeputy[i]=res.data[i].user_name
      }
      this.setData({
        columns_sche_moredeputy:this.data.columns_sche_moredeputy,
      })
    })
    this.data.show_sche_moredeputy[e.currentTarget.dataset.index]=true
    this.setData({
      //columns_opertime: ['A','B','AB','O'],   //选择器中的值
      show_sche_moredeputy: this.data.show_sche_moredeputy
    })
  },
  onClose_sche_moredeputy(e) {     //点击空白处开闭弹出层（选择器）及选择器左上角的取消
    for(var i=0;i<this.data.show_sche_moredeputy.length;i++){
      this.data.show_sche_moredeputy[i]=false
    }
    this.data.show_sche_moredeputy[e.currentTarget.dataset.index]=false
    this.setData({ show_sche_moredeputy: this.data.show_sche_moredeputy});
  },
  onConfirm_sche_moredeputy(e){    //选择器右上角的确定，点击确定获取值
    this.data.show_sche_moredeputy[e.currentTarget.dataset.index]=false
    this.data.gender_sche_moredeputy[e.currentTarget.dataset.index]=e.detail.value
    this.data.sche_moredeputy[e.currentTarget.dataset.index]=this.data.getChiefIdToSc2[e.detail.index].user_name
    this.setData({
      gender_sche_moredeputy:this.data.gender_sche_moredeputy,
      sche_moredeputy:this.data.sche_moredeputy,
      show_sche_moredeputy:this.data.show_sche_moredeputy
    })
  },
  //值班表页面副主治医师上拉框(结合添加更多)
  showPopup_sche_moreattend(e){      //点击选择性别，打开弹出层（选择器）
    db.collection("user").where({
    }).get().then(res=>{
      this.setData({
        getChiefIdToSc3:res.data,
        columns_sche_moreattend:[]
      })
      for(var i=0;i<res.data.length;i++){
        this.data.columns_sche_moreattend[i]=res.data[i].user_name
      }
      this.setData({
        columns_sche_moreattend:this.data.columns_sche_moreattend,
      })
    })
    this.data.show_sche_moreattend[e.currentTarget.dataset.index]=true
    this.setData({
      //columns_opertime: ['A','B','AB','O'],   //选择器中的值
      show_sche_moreattend: this.data.show_sche_moreattend
    })
  },
  onClose_sche_moreattend(e) {     //点击空白处开闭弹出层（选择器）及选择器左上角的取消
    for(var i=0;i<this.data.show_sche_moreattend.length;i++){
      this.data.show_sche_moreattend[i]=false
    }
    this.data.show_sche_moreattend[e.currentTarget.dataset.index]=false
    this.setData({ show_sche_moreattend: this.data.show_sche_moreattend});
  },
  onConfirm_sche_moreattend(e){    //选择器右上角的确定，点击确定获取值
    this.data.show_sche_moreattend[e.currentTarget.dataset.index]=false
    this.data.gender_sche_moreattend[e.currentTarget.dataset.index]=e.detail.value
    this.data.sche_moreattend[e.currentTarget.dataset.index]=this.data.getChiefIdToSc3[e.detail.index].user_name
    this.setData({
      gender_sche_moreattend:this.data.gender_sche_moreattend,
      sche_moreattend:this.data.sche_moreattend,
      show_sche_moreattend:this.data.show_sche_moreattend
    })
  },
  //值班表页面住院医师上拉框(结合添加更多)
  showPopup_sche_moreresi(e){      //点击选择性别，打开弹出层（选择器）
    db.collection("user").where({
    }).get().then(res=>{
      this.setData({
        getChiefIdToSc4:res.data,
        columns_sche_moreresi:[]
      })
      for(var i=0;i<res.data.length;i++){
        this.data.columns_sche_moreresi[i]=res.data[i].user_name
      }
      this.setData({
        columns_sche_moreresi:this.data.columns_sche_moreresi,
      })
    })
    this.data.show_sche_moreresi[e.currentTarget.dataset.index]=true
    this.setData({
      //columns_opertime: ['A','B','AB','O'],   //选择器中的值
      show_sche_moreresi: this.data.show_sche_moreresi
    })
  },
  onClose_sche_moreresi(e) {     //点击空白处开闭弹出层（选择器）及选择器左上角的取消
    for(var i=0;i<this.data.show_sche_moreresi.length;i++){
      this.data.show_sche_moreresi[i]=false
    }
    this.data.show_sche_moreresi[e.currentTarget.dataset.index]=false
    this.setData({ show_sche_moreresi: this.data.show_sche_moreresi});
  },
  onConfirm_sche_moreresi(e){    //选择器右上角的确定，点击确定获取值
    this.data.show_sche_moreresi[e.currentTarget.dataset.index]=false
    this.data.gender_sche_moreresi[e.currentTarget.dataset.index]=e.detail.value
    this.data.sche_moreresi[e.currentTarget.dataset.index]=this.data.getChiefIdToSc4[e.detail.index].user_name
    this.setData({
      gender_sche_moreresi:this.data.gender_sche_moreresi,
      sche_moreresi:this.data.sche_moreresi,
      show_sche_moreresi:this.data.show_sche_moreresi
    })
  },
  //值班表页面轮转医师上拉框(结合添加更多)
  showPopup_sche_morerota(e){      //点击选择性别，打开弹出层（选择器）
    db.collection("user").where({
    }).get().then(res=>{
      this.setData({
        getChiefIdToSc5:res.data,
        columns_sche_morerota:[]
      })
      for(var i=0;i<res.data.length;i++){
        this.data.columns_sche_morerota[i]=res.data[i].user_name
      }
      this.setData({
        columns_sche_morerota:this.data.columns_sche_morerota,
      })
    })
    this.data.show_sche_morerota[e.currentTarget.dataset.index]=true
    this.setData({
      //columns_opertime: ['A','B','AB','O'],   //选择器中的值
      show_sche_morerota: this.data.show_sche_morerota
    })
  },
  onClose_sche_morerota(e) {     //点击空白处开闭弹出层（选择器）及选择器左上角的取消
    for(var i=0;i<this.data.show_sche_morerota.length;i++){
      this.data.show_sche_morerota[i]=false
    }
    this.data.show_sche_morerota[e.currentTarget.dataset.index]=false
    this.setData({ show_sche_morerota: this.data.show_sche_morerota});
  },
  onConfirm_sche_morerota(e){    //选择器右上角的确定，点击确定获取值
    this.data.show_sche_morerota[e.currentTarget.dataset.index]=false
    this.data.gender_sche_morerota[e.currentTarget.dataset.index]=e.detail.value
    this.data.sche_morerota[e.currentTarget.dataset.index]=this.data.getChiefIdToSc5[e.detail.index].user_name
    this.setData({
      gender_sche_morerota:this.data.gender_sche_morerota,
      sche_morerota:this.data.sche_morerota,
      show_sche_morerota:this.data.show_sche_morerota
    })
  },
  //新增患者页面手术日期时间选择器
  showPopup_opertime(e){      //点击选择性别，打开弹出层（选择器）
    this.setData({
      //columns_opertime: ['A','B','AB','O'],   //选择器中的值
      show_opertime:true
    })
  },
  onClose_opertime() {     //点击空白处开闭弹出层（选择器）及选择器左上角的取消
    this.setData({ show_opertime: false });
  },
  onConfirm_opertime(e){    //选择器右上角的确定，点击确定获取值
    this.setData({
      gender_opertime:common.getMyData(e.detail,'Y-m-d'),
      patient_oper_list_time:e.detail,
      show_opertime:false
    })
  },
  onInput(event) {
    this.setData({
      currentDate: event.detail,
    });
    console.log(event)
  },
  //手术时间选择器（结合添加更多，没再写onInput函数）
  showPopup_patient_others_time(e){      //点击选择性别，打开弹出层（选择器）
    this.data.show_patient_others_time[e.currentTarget.dataset.index]=true
    this.setData({
      //columns_opertime: ['A','B','AB','O'],   //选择器中的值
      show_patient_others_time:this.data.show_patient_others_time
    })
  },
  onClose_patient_others_time(e) {     //点击空白处开闭弹出层（选择器）及选择器左上角的取消
    for(var i=0;i<this.data.show_patient_others_time.length;i++){
      this.data.show_patient_others_time[i]=false
    }
    this.data.show_patient_others_time[e.currentTarget.dataset.index]=false
    this.setData({ show_patient_others_time:this.data.show_patient_others_time });
  },
  onConfirm_patient_others_time(e){    //选择器右上角的确定，点击确定获取值
    this.data.show_patient_others_time[e.currentTarget.dataset.index]=false
    this.data.gender_patient_others_time[e.currentTarget.dataset.index]=common.getMyData(e.detail,'Y-m-d')
    this.data.patient_others[e.currentTarget.dataset.index].time=e.detail
    this.setData({
      gender_patient_others_time:this.data.gender_patient_others_time,
      patient_others:this.data.patient_others,
      show_patient_others_time:this.data.show_patient_others_time
    })
  },
  //总体情况页面手术日期时间选择器
  showPopup_ward_time(e){      //点击选择性别，打开弹出层（选择器）
    this.setData({
      //columns_opertime: ['A','B','AB','O'],   //选择器中的值
      show_ward_time:true,
      minDate_ward_time:this.data.minDate_ward_time
    })
  },
  onClose_ward_time() {     //点击空白处开闭弹出层（选择器）及选择器左上角的取消
    this.setData({ show_ward_time: false });
  },
  onConfirm_ward_time(e){    //选择器右上角的确定，点击确定获取值
    this.setData({
      gender_ward_time:common.getMyData(e.detail,'Y-m-d'),
      ward_time:e.detail,
      show_ward_time:false,
    })
    console.log(e.detail)
  },
  onInput_ward_time(event) {
    this.setData({
      currentDate_ward_time: event.detail,
    });
  },
  //值班表页面年月时间选择器
  showPopup_sche_time(e){      //点击选择性别，打开弹出层（选择器）
    this.setData({
      //columns_opertime: ['A','B','AB','O'],   //选择器中的值
      show_sche_time:true
    })
  },
  onClose_sche_time() {     //点击空白处开闭弹出层（选择器）及选择器左上角的取消
    this.setData({ show_sche_time: false });
  },
  onConfirm_sche_time(e){    //选择器右上角的确定，点击确定获取值
    this.setData({
      gender_sche_time:common.getMyData(e.detail,'Y-m'),
      sche_time:common.getMyData(e.detail,'Y-m'),
      show_sche_time:false
    })
    //确定表格的列数
    var list_date=new Date(e.detail)
    //将当前月份加1，下移到下一个月
    list_date.setMonth(list_date.getMonth()+1);
    //将当前的日期置为0，
    list_date.setDate(0);
    //再获取天数即取上个月的最后一天的天数
    var list_length=list_date.getDate();
    var sche_list=[]  //数组
    var show_sche_list=[]  //数组
    var gender_sche_list=[]  //数组
    for(var i=0;i<list_length;i++){
      show_sche_list[i]={"three":false,"two":false,"one":false,"attendant":false,"rota":false}
      sche_list[i]={"index":i+1,"three":"","two":"","one":"","attendant":"","rota":""}
      gender_sche_list[i]={"three":"","two":"","one":"","attendant":"","rota":""}
    }
    this.setData({
      sche_list:sche_list,
      show_sche_list:show_sche_list,
      gender_sche_list:gender_sche_list
    })
    this.setData({
      active_sche:0
    })
  },
  onInput(event) {
    this.setData({
      currentDate: event.detail,
    });
    console.log(event)
  },
  //值班表页面表格医师上拉框
  showPopup_sche_list(e){      //点击选择性别，打开弹出层（选择器）
    db.collection("user").where({
    }).get().then(res=>{
      this.setData({
        getChiefIdToSche2:res.data,
        columns_sche_list:[]
      })
      for(var i=0;i<res.data.length;i++){
        this.data.columns_sche_list[i]=res.data[i].user_name
      }
      this.setData({
        columns_sche_list:this.data.columns_sche_list,
      })
    })
    switch(e.currentTarget.dataset.key){
      case "three":this.data.show_sche_list[e.currentTarget.dataset.index].three=true;break; 
      case "two":this.data.show_sche_list[e.currentTarget.dataset.index].two=true;break; 
      case "one":this.data.show_sche_list[e.currentTarget.dataset.index].one=true;break; 
      case "attendant":this.data.show_sche_list[e.currentTarget.dataset.index].attendant=true;break; 
      case "rota":this.data.show_sche_list[e.currentTarget.dataset.index].rota=true;break; 
    }
    this.setData({
      show_sche_list:this.data.show_sche_list
    })
  },
  onClose_sche_list(e) {     //点击空白处开闭弹出层（选择器）及选择器左上角的取消
    console.log(this.data.show_sche_list)
    switch(e.currentTarget.dataset.key){
      case "three":this.data.show_sche_list[e.currentTarget.dataset.index].three=false;break; 
      case "two":this.data.show_sche_list[e.currentTarget.dataset.index].two=false;break; 
      case "one":this.data.show_sche_list[e.currentTarget.dataset.index].one=false;break; 
      case "attendant":this.data.show_sche_list[e.currentTarget.dataset.index].attendant=false;break; 
      case "rota":this.data.show_sche_list[e.currentTarget.dataset.index].rota=false;break; 
    }
    this.setData({ show_sche_list: this.data.show_sche_list });
  },
  onConfirm_sche_list(e){    //选择器右上角的确定，点击确定获取值
    switch(e.currentTarget.dataset.key){
      case "three":
        this.data.show_sche_list[e.currentTarget.dataset.index].three=false;
        this.data.gender_sche_list[e.currentTarget.dataset.index].three=e.detail.value
        this.data.sche_list[e.currentTarget.dataset.index].three=this.data.getChiefIdToSche2[e.detail.index]._openid
        break; 
      case "two":
        this.data.show_sche_list[e.currentTarget.dataset.index].two=false;
        this.data.gender_sche_list[e.currentTarget.dataset.index].two=e.detail.value
        this.data.sche_list[e.currentTarget.dataset.index].two=this.data.getChiefIdToSche2[e.detail.index]._openid
        break; 
      case "one":
        this.data.show_sche_list[e.currentTarget.dataset.index].one=false;
        this.data.gender_sche_list[e.currentTarget.dataset.index].one=e.detail.value
        this.data.sche_list[e.currentTarget.dataset.index].one=this.data.getChiefIdToSche2[e.detail.index]._openid
        break; 
      case "attendant":
        this.data.show_sche_list[e.currentTarget.dataset.index].attendant=false;
        this.data.gender_sche_list[e.currentTarget.dataset.index].attendant=e.detail.value
        this.data.sche_list[e.currentTarget.dataset.index].attendant=this.data.getChiefIdToSche2[e.detail.index]._openid
        break; 
      case "rota":
        this.data.show_sche_list[e.currentTarget.dataset.index].rota=false;
        this.data.gender_sche_list[e.currentTarget.dataset.index].rota=e.detail.value
        this.data.sche_list[e.currentTarget.dataset.index].rota=this.data.getChiefIdToSche2[e.detail.index]._openid
        break; 
    }
    this.setData({
      gender_sche_list:this.data.gender_sche_list,
      sche_list:this.data.sche_list,
      show_sche_list:this.data.show_sche_list
    })
  },
  
  

  //从patient数据库获取病人姓名给术后指标
  // getPatientToAo(){
  //   db.collection("patient").where({
  //     patient_del:false
  //   }).get().then(res=>{
  //     this.setData({
  //       getPatientIdToAo:res.data
  //     })
  //     for(var i=0;i<res.data.length;i++){
  //       this.data.option1[i+1]={ text: res.data[i].patient_name, value: i+1 }
  //     }
  //     this.setData({
  //       option1:this.data.option1
  //     })
  //   })
  // },
  //从patient数据库获取病人姓名给特殊交班并自动匹配输入相关数据(该数据只需取不需填入数据库)
  // getPatientToSs(event){
  //   db.collection("patient").where({
  //     patient_del:false
  //   }).get().then(res=>{
  //     this.setData({
  //       getPatientIdToSs:res.data
  //     })
  //     for(var i=0;i<res.data.length;i++){
  //       this.data.option2[i+1]={ text: res.data[i].patient_name, value: i+1 }
  //     }
  //     this.setData({
  //       option2:this.data.option2,
  //     })
  //   })
  // },
  //获取value并以此自动输入床号等
  // getValue(res){
    // if(res.detail==0){
    //   this.setData({
    //     value2:res.detail,
    //     ss_value:res.detail,
    //     ss_bed:"",
    //     ss_sex:"",
    //     ss_age:"",
    //     ss_situation:""
    //   })
    // }
    // console.log(res)
    // // 判断当前时间和手术时间，给ss_situation赋值
    // this.data.ss_situation=""     //先将ss_situation清零
    // if(res.detail!=0){
    //   for(var i=0;i<this.data.getPatientIdToSs[res.detail.index].patient_oper_list.length;i++){
    //     this.data.ss_situation=this.data.ss_situation+this.data.getPatientIdToSs[res.detail-1].patient_oper_list[i].name
    //     if(new Date().getTime()>=this.data.getPatientIdToSs[res.detail.index].patient_oper_list[i].time){
    //       this.data.ss_situation=this.data.ss_situation+"术后  "
    //     }else{
    //       this.data.ss_situation=this.data.ss_situation+"术前  "
    //     }
    //   }
    //   if(this.data.getPatientIdToSs[res.detail.index].patient_oper_list.length==0){
    //     this.data.ss_situation=this.data.ss_situation+"无"
    //   }
    //   this.setData({
    //     value2:res.detail,
    //     ss_value:res.detail,
    //     ss_bed:this.data.getPatientIdToSs[res.detail.index].patient_bed,
    //     ss_sex:this.data.getPatientIdToSs[res.detail.index].patient_sex,
    //     ss_age:this.data.getPatientIdToSs[res.detail.index].patient_age,
    //     ss_situation:this.data.ss_situation
    //   })
    // }
  // }, 
  //在点开的时候将value的值设为-1，以触发bind:change
  // changeValue(){
  //   this.setData({
  //     value2:-1
  //   })
  // },
  //从patient数据库获取病人姓名给总体情况（结合添加更多）
  // getPatientToWard(){
  //   db.collection("patient").where({
  //     patient_del:false
  //   }).get().then(res=>{
  //     this.setData({
  //       getPatientIdToWard:res.data
  //     })
  //     for(var i=0;i<res.data.length;i++){
  //       this.data.option5[i+1]={ text: res.data[i].patient_name, value: i+1 }
  //     }
  //     this.setData({
  //       option5:this.data.option5
  //     })
  //   })
  // },
  //获取ward_oper的name属性并改变数组（结合添加更多）
  // getValue_ward_opername(res){
  //   this.data.ward_oper[res.currentTarget.dataset.index].name=this.data.option5[res.detail].text
  //   this.setData({
  //     ward_oper:this.data.ward_oper
  //   })
  // },

  //添加更多的显示
  // patient_show(res){
  //   this.setData({
  //     patient_show_number:this.data.patient_show_number
  //   })
  //   switch(++this.data.patient_show_number){
  //     case 1:
  //       this.setData({
  //         patient_oper_list_name1:"position:relative",
  //         patient_oper_list_time1:"position:relative"
  //       })
  //   }
  // },
  ward_oper_show(res){
    this.data.ward_oper.push({"des":"","name":""})
    this.data.show_ward_opername.push()
    this.data.gender_ward_opername.push()
    this.setData({
      ward_oper:this.data.ward_oper,
      show_ward_opername:this.data.show_ward_opername,
      gender_ward_opername:this.data.gender_ward_opername
    })
    //判断今日手术部分是否都不是空的
    var ward_judge=false
    this.setData({
      ward_judge:ward_judge
    })
  },
  ward_bed_appoint_show(res){
    this.data.ward_bed_appoint.push("")
    this.setData({
      ward_bed_appoint:this.data.ward_bed_appoint
    })
  },
  ward_others_hos_show(res){
    this.data.ward_others_hos.push("")
    this.setData({
       ward_others_hos:this.data.ward_others_hos,
    })
  },
  ao_others_show(res){
    this.data.ao_others.push({"name":"","value":""})
    this.setData({
      ao_others:this.data.ao_others
    })
  },
  patient_others_show(res){
    this.data.patient_others.push({"name":"","time":""})
    this.data.show_patient_others_time.push()
    this.data.gender_patient_others_time.push()
    this.setData({
      patient_others:this.data.patient_others,
      show_patient_others_time:this.data.show_patient_others_time,
      gender_patient_others_time:this.data.gender_patient_others_time
    })
  },
  patient_otherchief_show(res){
    this.data.patient_otherchief.push("")
    this.data.show_patient_otherchief.push()
    this.data.gender_patient_otherchief.push()
    this.setData({
      patient_otherchief:this.data.patient_otherchief,
      show_patient_otherchief:this.data.show_patient_otherchief,
      gender_patient_otherchief:this.data.gender_patient_otherchief
    })
  },
  sche_morechief_show(res){
    this.data.sche_morechief.push("")
    this.data.show_sche_morechief.push()
    this.data.gender_sche_morechief.push()
    this.setData({
      sche_morechief:this.data.sche_morechief,
      show_sche_morechief:this.data.show_sche_morechief,
      gender_sche_morechief:this.data.gender_sche_morechief
    })
  },
  sche_moredeputy_show(res){
    this.data.sche_moredeputy.push("")
    this.data.show_sche_moredeputy.push()
    this.data.gender_sche_moredeputy.push()
    this.setData({
      sche_moredeputy:this.data.sche_moredeputy,
      show_sche_moredeputy:this.data.show_sche_moredeputy,
      gender_sche_moredeputy:this.data.gender_sche_moredeputy
    })
  },
  sche_moreattend_show(res){
    this.data.sche_moreattend.push("")
    this.data.show_sche_moreattend.push()
    this.data.gender_sche_moreattend.push()
    this.setData({
      sche_moreattend:this.data.sche_moreattend,
      show_sche_moreattend:this.data.show_sche_moreattend,
      gender_sche_moreattend:this.data.gender_sche_moreattend
    })
  },
  sche_moreresi_show(res){
    this.data.sche_moreresi.push("")
    this.data.show_sche_moreresi.push()
    this.data.gender_sche_moreresi.push()
    this.setData({
      sche_moreresi:this.data.sche_moreresi,
      show_sche_moreresi:this.data.show_sche_moreresi,
      gender_sche_moreresi:this.data.gender_sche_moreresi
    })
  },
  sche_morerota_show(res){
    this.data.sche_morerota.push("")
    this.data.show_sche_morerota.push()
    this.data.gender_sche_morerota.push()
    this.setData({
      sche_morerota:this.data.sche_morerota,
      show_sche_morerota:this.data.show_sche_morerota,
      gender_sche_morerota:this.data.gender_sche_morerota
    })
  },

  //添加更多的删除
  ward_oper_clear(res){
    this.data.ward_oper.splice(res.currentTarget.dataset.index,1)
    this.data.show_ward_opername.splice(res.currentTarget.dataset.index,1)
    this.data.gender_ward_opername.splice(res.currentTarget.dataset.index,1)
    this.setData({
      ward_oper:this.data.ward_oper,
      show_ward_opername:this.data.show_ward_opername,
      gender_ward_opername:this.data.gender_ward_opername
    })
    //判断今日手术部分是否都不是空的
    var ward_judge=true
    for(var i=0;i<this.data.ward_oper.length;i++){
      if(this.data.ward_oper[i].name==''||this.data.ward_oper[i].des==''){
        ward_judge=false;
        break;
      }
    }
    this.setData({
      ward_judge:ward_judge
    })
  },
  ward_bed_appoint_clear(res){
    this.data.ward_bed_appoint.splice(res.currentTarget.dataset.index,1)
    this.setData({
      ward_bed_appoint:this.data.ward_bed_appoint
    })
  },
  ward_others_hos_clear(res){  
    this.data.ward_others_hos.splice(res.currentTarget.dataset.index,1)
    this.setData({
       ward_others_hos:this.data.ward_others_hos,
    })
  },
  ao_others_clear(res){
    this.data.ao_others.splice(res.currentTarget.dataset.index,1)
    this.setData({
      ao_others:this.data.ao_others
    })
  },
  patient_others_clear(res){
    this.data.patient_others.splice(res.currentTarget.dataset.index,1)
    this.data.show_patient_others_time.splice(res.currentTarget.dataset.index,1)
    this.data.gender_patient_others_time.splice(res.currentTarget.dataset.index,1)
    this.setData({
      patient_others:this.data.patient_others,
      show_patient_others_time:this.data.show_patient_others_time,
      gender_patient_others_time:this.data.gender_patient_others_time
    })
  },
  patient_otherchief_clear(res){
    this.data.patient_otherchief.splice(res.currentTarget.dataset.index,1)
    this.data.show_patient_otherchief.splice(res.currentTarget.dataset.index,1)
    this.data.gender_patient_otherchief.splice(res.currentTarget.dataset.index,1)
    this.setData({
      patient_otherchief:this.data.patient_otherchief,
      show_patient_otherchief:this.data.show_patient_otherchief,
      gender_patient_otherchief:this.data.gender_patient_otherchief
    })
  },
  sche_morechief_clear(res){
    this.data.sche_morechief.splice(res.currentTarget.dataset.index,1)
    this.data.show_sche_morechief.splice(res.currentTarget.dataset.index,1)
    this.data.gender_sche_morechief.splice(res.currentTarget.dataset.index,1)
    this.setData({
      sche_morechief:this.data.sche_morechief,
      show_sche_morechief:this.data.show_sche_morechief,
      gender_sche_morechief:this.data.gender_sche_morechief
    })
  },
  sche_moredeputy_clear(res){
    this.data.sche_moredeputy.splice(res.currentTarget.dataset.index,1)
    this.data.show_sche_moredeputy.splice(res.currentTarget.dataset.index,1)
    this.data.gender_sche_moredeputy.splice(res.currentTarget.dataset.index,1)
    this.setData({
      sche_moredeputy:this.data.sche_moredeputy,
      show_sche_moredeputy:this.data.show_sche_moredeputy,
      gender_sche_moredeputy:this.data.gender_sche_moredeputy
    })
  },
  sche_moreattend_clear(res){
    this.data.sche_moreattend.splice(res.currentTarget.dataset.index,1)
    this.data.show_sche_moreattend.splice(res.currentTarget.dataset.index,1)
    this.data.gender_sche_moreattend.splice(res.currentTarget.dataset.index,1)
    this.setData({
      sche_moreattend:this.data.sche_moreattend,
      show_sche_moreattend:this.data.show_sche_moreattend,
      gender_sche_moreattend:this.data.gender_sche_moreattend
    })
  },
  sche_moreresi_clear(res){
    this.data.sche_moreresi.splice(res.currentTarget.dataset.index,1)
    this.data.show_sche_moreresi.splice(res.currentTarget.dataset.index,1)
    this.data.gender_sche_moreresi.splice(res.currentTarget.dataset.index,1)
    this.setData({
      sche_moreresi:this.data.sche_moreresi,
      show_sche_moreresi:this.data.show_sche_moreresi,
      gender_sche_moreresi:this.data.gender_sche_moreresi
    })
  },
  sche_morerota_clear(res){
    this.data.sche_morerota.splice(res.currentTarget.dataset.index,1)
    this.data.show_sche_morerota.splice(res.currentTarget.dataset.index,1)
    this.data.gender_sche_morerota.splice(res.currentTarget.dataset.index,1)
    this.setData({
      sche_morerota:this.data.sche_morerota,
      show_sche_morerota:this.data.show_sche_morerota,
      gender_sche_morerota:this.data.gender_sche_morerota
    })
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //总体情况页面相关功能
    //病人总数——从patient数据库获取病人数量输出到总体情况
    db.collection("patient").where({
      patient_del:false
    }).get().then(res=>{
      this.setData({
        ward_patient_number:res.data.length
      })
    })
    //在院术前评估的血型——从bo数据库获取在院和血型符合的
    db.collection("bo").where({
      bo_bed:"院内",
      bo_blood_type:"A"
    }).get().then(res=>{
      this.setData({
        ward_bef_A:res.data.length
      })
    })
    db.collection("bo").where({
      bo_bed:"院内",
      bo_blood_type:"B"
    }).get().then(res=>{
      this.setData({
        ward_bef_B:res.data.length
      })
    })
    db.collection("bo").where({
      bo_bed:"院内",
      bo_blood_type:"AB"
    }).get().then(res=>{
      this.setData({
        ward_bef_AB:res.data.length
      })
    })
    db.collection("bo").where({
      bo_bed:"院内",
      bo_blood_type:"O"
    }).get().then(res=>{
      this.setData({
        ward_bef_O:res.data.length
      })
    })
    //院外等待手术的血型——从bo数据库获取院外和血型符合的
    db.collection("bo").where({
      bo_bed:_.in(["院外","儿科"]),
      bo_blood_type:"A"
    }).get().then(res=>{
      this.setData({
        ward_wait_A:res.data.length
      })
    })
    db.collection("bo").where({
      bo_bed:_.in(["院外","儿科"]),
      bo_blood_type:"B"
    }).get().then(res=>{
      this.setData({
        ward_wait_B:res.data.length
      })
    })
    db.collection("bo").where({
      bo_bed:_.in(["院外","儿科"]),
      bo_blood_type:"AB"
    }).get().then(res=>{
      this.setData({
        ward_wait_AB:res.data.length
      })
    })
    db.collection("bo").where({
      bo_bed:_.in(["院外","儿科"]),
      bo_blood_type:"O"
    }).get().then(res=>{
      this.setData({
        ward_wait_O:res.data.length
      })
    })
    db.collection("ward").where({
      ward_submit:false
    }).get().then(res=>{
      if(res.data[0].ward_time.getTime()>new Date().getTime()){
        this.setData({
        minDate_ward_time:res.data[0].ward_time.getTime(),
        ward_time:res.data[0].ward_time.getTime(),
        gender_ward_time:"",
        ward_lastid:res.data[0]._id
      })
      }else{
        this.setData({
          minDate_ward_time:res.data[0].ward_time.getTime(),
          ward_time:res.data[0].ward_time.getTime(),
          gender_ward_time:common.getMyData(res.data[0].ward_time.getTime(),'Y-m-d'),
          ward_lastid:res.data[0]._id
        })
      }
    })


    //添加更多——动态添加veiw
    //总体情况页面的添加病人姓名和手术名称
    //var ward_oper=[{"des":"","name":""}]
    var ward_oper=[]
    var show_ward_opername=[]
    var gender_ward_opername=[]
    this.setData({
      ward_oper:ward_oper,
      show_ward_opername:show_ward_opername,
      gender_ward_opername:gender_ward_opername
    })
    //总体情况页面的拟住院约床和900医院
    var ward_bed_appoint=[]
    var ward_others_hos=[]
    this.setData({
      ward_bed_appoint:ward_bed_appoint,
       ward_others_hos: ward_others_hos,
    })
    //术后指标页面的指标数据
    var ao_others=[]
    this.setData({
      ao_others:ao_others
    })
    //新增患者页面的手术类型和手术日期，统一归到一个对象数组
    var patient_others=[]
    var show_patient_others_time=[]
    var gender_patient_others_time=[]
    this.setData({
      patient_others:patient_others,
      show_patient_others_time:show_patient_others_time,
      gender_patient_others_time:gender_patient_others_time
    })
    //新增患者页面的主管医师
    var patient_otherchief=[]
    var show_patient_otherchief=[]
    var gender_patient_otherchief=[]
    this.setData({
      patient_otherchief:patient_otherchief,
      show_patient_otherchief:show_patient_otherchief,
      gender_patient_otherchief:gender_patient_otherchief
    })
    //值班表页面的医师（多输入框合一）
    var sche_otherchief=["","","","","","","",""]  //数组
    var show_sche_otherchief=["","","","","","","",""]  //数组
    var gender_sche_otherchief=["","","","","","","",""]  //数组
    this.setData({
      sche_otherchief:sche_otherchief,
      show_sche_otherchief:show_sche_otherchief,
      gender_sche_otherchief:gender_sche_otherchief,
    })
    //值班表页面的主任医师（结合添加更多）
    var sche_morechief=[]
    var show_sche_morechief=[]
    var gender_sche_morechief=[]
    this.setData({
      sche_morechief:sche_morechief,
      show_sche_morechief:show_sche_morechief,
      gender_sche_morechief:gender_sche_morechief
    })
    //值班表页面的副主任医师（结合添加更多）
    var sche_moredeputy=[]
    var show_sche_moredeputy=[]
    var gender_sche_moredeputy=[]
    this.setData({
      sche_moredeputy:sche_moredeputy,
      show_sche_moredeputy:show_sche_moredeputy,
      gender_sche_moredeputy:gender_sche_moredeputy
    })
    //值班表页面的主治医师（结合添加更多）
    var sche_moreattend=[]
    var show_sche_moreattend=[]
    var gender_sche_moreattend=[]
    this.setData({
      sche_moreattend:sche_moreattend,
      show_sche_moreattend:show_sche_moreattend,
      gender_sche_moreattend:gender_sche_moreattend
    })
    //值班表页面的住院医师（结合添加更多）
    var sche_moreresi=[]
    var show_sche_moreresi=[]
    var gender_sche_moreresi=[]
    this.setData({
      sche_moreresi:sche_moreresi,
      show_sche_moreresi:show_sche_moreresi,
      gender_sche_moreresi:gender_sche_moreresi
    })
    //值班表页面的轮转医师（结合添加更多）
    var sche_morerota=[]
    var show_sche_morerota=[]
    var gender_sche_morerota=[]
    this.setData({
      sche_morerota:sche_morerota,
      show_sche_morerota:show_sche_morerota,
      gender_sche_morerota:gender_sche_morerota
    })
    //值班表页面的表格医师（多输入框合一）
    var sche_list=[]  //数组
    var show_sche_list=[]  //数组
    var gender_sche_list=[]  //数组
    this.setData({
      sche_list:sche_list,
      show_sche_list:show_sche_list,
      gender_sche_list:gender_sche_list,
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})
